package Demo5.Demo1;

/**
 * @Author:LiRegin
 * @Date: 2019/12/4 20:30:51
 */
public class Demo1 {
    public static void main(String[] args) throws Exception { ;
        int i=stringToNumber("123");
        System.out.println(i);
    }
    public static int stringToNumber(String s) throws Exception {
        boolean a=false;
        int i=0;
        if (s==null){
            throw new Exception("字符串不能为null");
        }
        try {
            i=Integer.parseInt(s);
        } catch (NumberFormatException e) {
            a=true;
        }
        if (s.equals("")){
            throw new Exception("字符串不能为空");
        }if (a){
            throw new Exception("字符串转换失败");
        }
        return i;
    }
}
